package com.linzm.structuraltype.adapter01.mediaplayer;

import com.linzm.structuraltype.adapter01.enums.MediaTypeEnum;

/**
 * @Author zimingl
 * @Date 2023/4/15 22:45
 * @Description: AudioPlayer
 */
public class AudioPlayer implements MediaPlayer {
    MediaAdapter mediaAdapter;

    @Override
    public void play(String audioType, String fileName) throws Exception {
        //播放 mp3 音乐文件的内置支持
        if (MediaTypeEnum.MP3.name().equalsIgnoreCase(audioType)) {
            System.out.println("Playing mp3 file. Name: " + fileName);
        }
        //mediaAdapter 提供了播放其他文件格式的支持
        else if (MediaTypeEnum.MP4.name().equalsIgnoreCase(audioType)
                || MediaTypeEnum.VLC.name().equalsIgnoreCase(audioType)) {
            mediaAdapter = new MediaAdapter(audioType);
            mediaAdapter.play(audioType, fileName);
        } else {
            System.out.println("Invalid media. " +
                    audioType + " format not supported");
        }
    }
}
